<template>
    <div>
        <h1>医生列表</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>编号</td>
                    <td>姓名</td>
                    <td>头像</td>
                    <td>科室</td>
                    <td>创建日期</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="d in data">
                    <td>{{d.yid}}</td>
                    <td>{{ d.yname }}</td>
                    <td>
                        <img :src="'https://localhost:7215/'+d.imgUrl" style="width: 60px;height: 60px;">
                    </td>
                    <td>{{ d.kname }}</td>
                    <td>{{ moment(d.yCreateTime).format("yyyy-MM-DD hh:mm:ss") }}</td>
                </tr>
            </tbody>
        </table>
        一共{{ cs.pcount }}页,一共{{ cs.count }}条,当前第{{ cs.index }}页,每页{{ cs.size }}条
        <br>
        <input type="button" value="首页" @click="fan(1)">
        <input type="button" value="上一页" @click="fan(2)">

        <input type="button" v-for="d in cs.pcount" :value="d" @click="shows(d)">

        <input type="button" value="下一页" @click="fan(3)">
        <input type="button" value="尾页" @click="fan(4)">
        <select v-model="cs.size" @change="yrl">
            <option value="3">每页3条</option>
            <option value="5">每页5条</option>
            <option value="7">每页7条</option>
        </select>
        <input type="number" v-model="cs.index">
        <input type="button" value="跳转" @click="tz">
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios';
import moment from 'moment';
import { useRouter } from 'vue-router';
const router=useRouter()
//页码按钮
const shows=(d:any)=>{
    cs.value.index=d
    show()
}
//跳转
const tz=()=>{
    if(cs.value.index>0 && cs.value.index<=cs.value.pcount){
        show()
    }
    else{
        cs.value.index=1
        show()
    }
}
//页容量
const yrl=()=>{
    cs.value.index=1
    show()
}
//翻页
const fan=(m:any)=>{
    if(m==1){
        cs.value.index=1
        show()
    }

    if(m==2){
        if(cs.value.index>1){
            cs.value.index-=1
            show()
        }
    }

    if(m==3){
        if(cs.value.index<cs.value.pcount){
            cs.value.index+=1
            show()
        }
    }

    if(m==4){
        cs.value.index=cs.value.pcount
        show()
    }
}

const data=ref([
    {
      "yid": 1,
      "yname": "张三",
      "imgUrl": "/ds/202513191113421.png",
      "yCreateTime": "2025-05-19T11:14:01.0849829",
      "kid": 1,
      "kname": "产科"
    }
])
//文档就绪
onMounted(()=>{
    show()
})
//参数
const cs=ref({
    index:1,
    size:3,
    count:0,
    pcount:0
})
//显示
const show=()=>{
    axios.get("/api/Ys/GetYs",{params:cs.value}).then(res=>{
        data.value=res.data.data
        cs.value.count=res.data.count
        cs.value.pcount=Math.ceil(cs.value.count/cs.value.size)
    })
}
</script>

<style scoped>

</style>